require(['goSwiper','loading','wx-footer'], function(goSwiper,loading,wxFooter) {
	var fristG = true;
	var pageNo=1;
	var allList=[];
	var skip=0;
	var	showSz=6;
	//轮播图
	setTimeout(function(){
		var swiper = new Swiper('.wz_swiper1', {
		    pagination: '.swiper-pagination',
		    paginationClickable: true,
		    autoplay: 3000,
		    autoplayDisableOnInteraction: false,
		    centeredSlides: true,
		    loop: true
		});
	},500);
    //实例化
    var bulk = new Vue({
        el: '#bulk',
        data: {
            bulkData: [],
            showLoading: false,
            apiUrl: wxUrl + '/v3.2/ttrader/list.do',
            item: {
                params:{
                    token: token,
                    userToken: userToken,
                    pageNo:pageNo,
                    pageSize:50
                }
            }
        },
/*        ready: function() {
            this.getIndexData()
        },*/
        methods: {
            getIndexData: function() {
                this.$http.get(this.apiUrl, this.item)
                    .then(function(response) {
						var result = JSON.parse(response.body);
						var bulkList = result.data.list;
						if(bulkList!=null && bulkList.length>0){
							allList = allList.concat(bulkList);
							this.item.params.pageNo++;
						}
						if(fristG){
							this.pushBulkData();
							fristG=false;
						}
                    },function(response) {
                        //console.log(response)
                    });
            },
			getMore:function(){
                this.getIndexData();
				this.pushBulkData();
            },
			pushBulkData:function(){
				var toSkip = skip+showSz;
				var t_allListLength = allList.length;
				if(t_allListLength > skip){
					if(t_allListLength>toSkip){
						this.bulkData = this.bulkData.concat(allList.slice(skip,toSkip));
						skip=toSkip;
					}else{
						var newArry = allList.slice(skip,t_allListLength);
						this.bulkData.push.apply(this.bulkData,newArry);
						skip = t_allListLength;
					}
				}
			},
            init: function () {
                this.getIndexData();
            }
        },
        directives: { // 自定义指令
            scroll: {
                bind: function(el, binding) {
                    window.addEventListener('scroll', function() {
                        if($(window).scrollTop() + $(window).height() == $(document).height()) {
                            bulk.getMore();
                        }
                    })
                }
            }
        }
    });
    bulk.init();
});

// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});